<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>作者博客：百度"three.js 郭隆邦"</title>
  <style>
    body{
            margin: 0;
            overflow: hidden;//隐藏body窗口区域滚动条
        }
    </style>
  <!--引入three.js三维引擎-->
  <script src="http://www.yanhuangxueyuan.com/versions/threejsR92/build/three.js"></script>
  <!-- 引入threejs扩展控件OrbitControls.js -->
  <script src="http://www.yanhuangxueyuan.com/versions/threejsR92/examples/js/controls/OrbitControls.js"></script>
  <script type="text/javascript" src="http://www.yanhuangxueyuan.com/threejs/examples/js/postprocessing/EffectComposer.js"></script>

  <!-- EffectComposer依赖RenderPass.js、ShaderPass.js、CopyShader.js库 -->
  <script type="text/javascript" src="http://www.yanhuangxueyuan.com/threejs/examples/js/postprocessing/RenderPass.js"></script>
  <script type="text/javascript" src="http://www.yanhuangxueyuan.com/threejs/examples/js/postprocessing/ShaderPass.js"></script>
  <script type="text/javascript" src="http://www.yanhuangxueyuan.com/threejs/examples/js/shaders/CopyShader.js"></script>

  <!-- GlitchPass.js通道效果：模拟电视屏效果  -->
  <script type="text/javascript" src="http://www.yanhuangxueyuan.com/threejs/examples/js/postprocessing/FilmPass.js"></script>
  <!-- FilmShader依赖FilmShader.js文件提供的后处理着色器代码 -->
  <script type="text/javascript" src="http://www.yanhuangxueyuan.com/threejs/examples/js/shaders/FilmShader.js"></script>
</head>

<body>
  <script>
    /**
     * 创建场景对象
     */
    var scene = new THREE.Scene();
    /**
     * 创建网格模型
     */
    var plane = new THREE.SphereGeometry(30, 25, 25); //创建一个立方体几何对象

    var material = new THREE.MeshLambertMaterial({
      color: 0x0000ff,
    }); //材质对象

    var mesh = new THREE.Mesh(plane, material); //网格模型对象
    scene.add(mesh); //网格模型添加到场景中

    /**
     * 光源设置
     */
    //点光源
    var point = new THREE.PointLight(0xffffff);
    point.position.set(400, 200, 300); //点光源位置
    scene.add(point); //点光源添加到场景中
    //环境光
    var ambient = new THREE.AmbientLight(0x444444);
    scene.add(ambient);
    /**
     * 相机设置
     */
    var width = window.innerWidth; //窗口宽度
    var height = window.innerHeight; //窗口高度
    var k = width / height; //窗口宽高比
    var s = 40; //三维场景缩放系数
    //创建相机对象
    var camera = new THREE.OrthographicCamera(-s * k, s * k, s, -s, 1, 1000);
    camera.position.set(0, 0, 200); //设置相机位置
    camera.lookAt(scene.position); //设置相机方向(指向的场景对象)
    /**
     * 创建渲染器对象
     */
    var renderer = new THREE.WebGLRenderer({
      antialias: true
    });
    renderer.setSize(width, height);
    renderer.setClearColor(0xb9d3ff, 1); //设置背景颜色
    document.body.appendChild(renderer.domElement); //body元素中插入canvas对象


    // 创建一个渲染器通道，场景和相机作为参数
    var renderPass = new THREE.RenderPass(scene, camera);
    // 创建FilmPass通道，模拟电视屏效果
    var FilmPass = new THREE.FilmPass(0.3, 0.4, 512, false);
    // 后处理完成，设置renderToScreen为true，后处理结果在Canvas画布上显示
    FilmPass.renderToScreen = true;

    // 创建后处理对象EffectComposer，WebGL渲染器作为参数
    var composer = new THREE.EffectComposer(renderer);
    // 设置renderPass通道
    composer.addPass(renderPass);
    // 设置FilmPass通道
    composer.addPass(FilmPass);

    function render() {
      // 使用后处理模块EffectComposer，可通过该对象的render方法调用渲染器的render方法
      composer.render();
      requestAnimationFrame(render);
    }
    render();
    var controls = new THREE.OrbitControls(camera,renderer.domElement); //创建控件对象
  </script>
</body>

</html>
